package edu.sysu.cshare.gui;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.UIManager;

import edu.sysu.cshare.dao.User;
import edu.sysu.cshare.util.GUI;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import java.awt.CardLayout;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;

import com.lowagie.text.Image;

import sun.java2d.loops.ScaledBlit;
import java.awt.Toolkit;

public class App_Main {

	private JFrame frmCshare;
	private User actor;
	private JPanel pnlMain;


	public User getActor() {
		return actor;
	}

	public void setActor(User actor) {
		this.actor = actor;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					App_Main window = new App_Main();

					window.frmCshare.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public App_Main() {

		/*
		 * Dlg_Login dialog = new Dlg_Login(this); dialog.toFront();
		 * dialog.setModal(true);
		 * dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		 * dialog.setVisible(true);
		 */
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			// GUI.setUIFont(new
			// javax.swing.plaf.FontUIResource("宋体",Font.PLAIN,14));
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		frmCshare = new JFrame();
		frmCshare.setIconImage(Toolkit.getDefaultToolkit().getImage(App_Main.class.getResource("/edu/sysu/cshare/image/CShare_32.png")));

		frmCshare.setBounds(100, 100, 803, 603);
		frmCshare.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		Dlg_Login dlg_Login = new Dlg_Login();
		GUI.showModalDialog(dlg_Login);
		this.actor=dlg_Login.getUser();
		System.out.println(actor.getName()+" 登陆成功");
		
		frmCshare.setTitle("CShare 1.0 欢迎回来" + actor.getName());
		frmCshare.getContentPane().setLayout(new BorderLayout(0, 0));
		
		pnlMain = new JPanel();
		frmCshare.getContentPane().add(pnlMain, BorderLayout.CENTER);
		pnlMain.setLayout(new CardLayout(0, 0));
		
		Pnl_Homework pnl_Homework = new Pnl_Homework();
		pnlMain.add(pnl_Homework, "Homework");
		
		Pnl_Message pnl_Message = new Pnl_Message();
		pnlMain.add(pnl_Message, "Message");
		
		

		JPanel pnlStatus = new JPanel();
		frmCshare.getContentPane().add(pnlStatus, BorderLayout.SOUTH);
		pnlStatus.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JLabel lblHomeworkStatus = new JLabel("作业:未交/总数");
		pnlStatus.add(lblHomeworkStatus);
		
		JLabel lblMessageStatus = new JLabel("消息: 新/总数");
		pnlStatus.add(lblMessageStatus);

		JProgressBar progressBar = new JProgressBar();
		pnlStatus.add(progressBar);

		JLabel lblTime = new JLabel("Time:");
		pnlStatus.add(lblTime);

		JPanel pnlOption = new JPanel();
		frmCshare.getContentPane().add(pnlOption, BorderLayout.NORTH);
		pnlOption.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JButton btnHomework = new JButton("");
		btnHomework.setToolTipText("作业管理");
		btnHomework.setVerticalTextPosition(SwingConstants.BOTTOM);
		btnHomework.setVerticalAlignment(SwingConstants.BOTTOM);
	
		
		btnHomework.setHorizontalTextPosition(SwingConstants.CENTER);
		btnHomework.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/homework_64.png")));
		btnHomework.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)pnlMain.getLayout();
				cl.show(pnlMain, "Homework");
				
			}
		});
		pnlOption.add(btnHomework);

		JButton btnMsg = new JButton("");
		btnMsg.setToolTipText("消息管理");
		btnMsg.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/message_64.png")));
		btnMsg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cl = (CardLayout)pnlMain.getLayout();
				cl.show(pnlMain, "Message");
			}
		});
		pnlOption.add(btnMsg);

		JButton btnSharing = new JButton("");
		btnSharing.setToolTipText("文件共享");
		btnSharing.setVerticalAlignment(SwingConstants.BOTTOM);
		btnSharing.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/share2_64.png")));
		pnlOption.add(btnSharing);

		JButton btnSetting = new JButton("");
		btnSetting.setToolTipText("系统设置");
		btnSetting.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/setting2_64.png")));
		btnSetting.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		pnlOption.add(btnSetting);

		JButton btnHelp = new JButton("");
		btnHelp.setToolTipText("帮助中心");
		btnHelp.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/help2_64.png")));
		pnlOption.add(btnHelp);

		JButton btnQuit = new JButton("");
		btnQuit.setToolTipText("退出系统");
		btnQuit.setIcon(new ImageIcon(App_Main.class.getResource("/edu/sysu/cshare/image/quit_64.png")));
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(1);
			}
		});
		pnlOption.add(btnQuit);
		/*
		 * pnl_Message = new Pnl_Message(); pnl_Homework = new Pnl_Homework();
		 * 
		 * 
		 * layeredPane.add("Homework", pnl_Homework);
		 * layeredPane.add("Setting",new Frm_Setting());
		 * layeredPane.add("Message", pnl_Message);
		 */
		/*
		 * layeredPane.add(pnl_Homework, 10); layeredPane.add(pnl_Message, 20);
		 * 
		 * pnl_Homework.setVisible(true);
		 * pnl_Homework.setBounds(pnl_Homework.getRootPane().getBounds());
		 * 
		 * pnl_Message.setVisible(true);
		 * pnl_Message.setBounds(pnl_Message.getRootPane().getBounds());
		 */
	}
}
